import request from '../../utils/request';
const publicWelfare = {
  state: {

  },

  getters: {

  },

  mutations: {

  },

  actions: {
    /**
     * 公益项目-列表
     * @payload{
     *  pageNum  string 
     *  pageSize string
     *  title string 
     *  state string  状态，progressing("进行中"), finished("已完成");
     *  id     string 
     *  startDay string 
     *  endDay   string 
     * }
     * */ 
    GET_PROJECT_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/project/list.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 公益项目-新建/更新
     * @payload{
     *  id  string  为null 新增，不为null更新
     *  title string 
     *  content string
     *  picture string
     *  state string  状态，progressing("进行中"), finished("已完成"); deleted删除
     *  targetMoney string 目标筹款额
     *  money string 
     * }
     * */ 
    UPDATE_PROJECT({}, payload) {
      return new Promise((resolve, reject) => {
        request.post('/project/save.htm', payload).then(res => {
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 公益项目-详情
     * @payload{
     *  id  string  
     * }
     * */ 
    GET_PROJECT_DETAIL({}, payload) {
      return new Promise((resolve, reject) => {
        request.post('/project/detail.htm', payload).then(res => {
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 公益项目-进度列表
     * @payload{
     *  projectId  string  
     *  pageNum string 
     *  pageSize string
     * }
     * */ 
    GET_PROJECT_PROGRESS_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/project/progressList.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 公益项目-新建进度/更新进度
     * @payload{
     *  projectId  string  项目id
     *  name string 进度名称
     *  description string 进度描述
     *  picUrl string 进度图片
     *  createTime string 创建时间
     *  id string 进度id
     * }
     * */ 
    UPDATE_PROJECT_PROGRESS({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/project/saveProgress.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 公益项目-捐款记录
     * @payload{
     *  projectId  string  
     *  pageNum string 
     *  pageSize string
     * }
     * */ 
    GET_DONATION_RECORD({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/project/logList.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    }

  }
}

export default publicWelfare